package com.lcg.word.screen

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.lcg.base.L
import com.lcg.word.Base
import com.lcg.word.BaseViewModel
import com.lcg.word.bean.BookUnit
import com.lcg.word.bean.wordDao
import com.lcg.word.ui.theme.Purple80
import com.lcg.word.viewModel
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator

/**
 * 消消乐
 *
 * @author lei.chuguang Email:475825657@qq.com
 */
@Preview
@Composable
@Destination
fun LinkScreen(
    navigator: DestinationsNavigator? = null,
    unit: BookUnit = BookUnit(),
    vm: LinkVM = viewModel(navigator, unit.name ?: "")
) {
    LaunchedEffect(Unit) {
        vm.load(unit)
    }
    Base(vm) {
        repeat(6) {
            Row(
                Modifier
                    .fillMaxWidth()
                    .weight(1f)
            ) {
                repeat(4) {
                    Box(
                        modifier = Modifier
                            .fillMaxHeight()
                            .weight(1f)
                            .padding(6.dp)
                            .background(Purple80)
                            .clickable {
                                L.i("---------")
                            }, contentAlignment = Alignment.Center
                    ) {
                        Text("111", color = Color.White)
                    }
                }
            }
        }
    }
}

class LinkVM : BaseViewModel() {
    fun load(unit: BookUnit) {
        val words = wordDao.queryForEq("unit_id", unit.id) as ArrayList
    }
}